<?php



namespace app\superadmin\controller;


use app\common\controller\SuperadminBase;
use think\Controller;

use think\Request;

use think\Session;

use think\Db;

use app\superadmin\model\User as Model;




class User extends SuperadminBase

{

    public function index()

    {   
        return $this->fetch();

    }



    public function gList(Request $request) {

         //获取每页显示的条数

        $limit= $request->param('limit');

        //获取当前页数

        $page= $request->param('page');


        $name = $request->param('name');

        $is_staff = $request->param('is_staff');

        $where = [];

        if (!empty($is_staff)) {
           
           $where['is_staff'] = $is_staff-1;
        }
       
        if (!empty($name)) {
            $list = Model::where('name|remark', 'like', '%' . $name . '%')->where($where)->order('create_time','desc')->paginate($limit,false,['page'=>$page])->toArray();    
        }else{

            $list = Model::where($where)->order('create_time','desc')->paginate($limit,false,['page'=>$page])->toArray();    

        }
        

        return json(['code'=>0,'msg'=>'','count'=>$list['total'],'data'=>$list['data']]);

    }



    public function editSxj()

    {
        $id    = $this->request->param('id');
        $is_xj = $this->request->param('is_xj');

        $info = Model::where('id', $id)->update(['is_staff'=>$is_xj]);

        return 1;

       
    }



    public function editpx()

    {
        $id   = $this->request->param('id');
        $remark = $this->request->param('remark');

        $info = Model::where('id', $id)->update(['remark'=>$remark]);

        return 1;

       
    }




        // 编辑
    public function edit()
    {   

        if(\request()->isPost()){

            $data  = input('post.');
           
            Model::where('id',$data['id'])->update($data);

            return json(['code'=>1, 'message'=>'修改成功']);


        }else{

            $id  = input('id');

            $info = Model::where('id',$id)->find();

            $this->assign('info', $info);

            return $this->fetch();

        }
        
    }







}

